﻿#region LGPL License

/*
OpenSearchNet
Copyright (c) 2014, Brad Hards <bradh@frogmouth.net>, All rights reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library.
*/

#endregion LGPL License

using System;

namespace OpenSearch
{
    /// <summary>
    /// Represents a Link element in a query response
    /// </summary>
    public class Link
    {
        private System.ServiceModel.Syndication.SyndicationLink rawLink;

        /// <summary>
        /// Build processed Link from raw SyndicationLink
        /// </summary>
        /// <param name="rawLink">SyndicationLink to process</param>
        public Link(System.ServiceModel.Syndication.SyndicationLink rawLink)
        {
            this.rawLink = rawLink;
        }

        /// <summary>
        /// URL for the link
        /// </summary>
        public Uri Href
        {
            get { return rawLink.Uri; }
        }

        /// <summary>
        /// Relation for the link
        /// </summary>
        /// <remarks>
        /// <para>
        /// This corresponds to the Atom <c>rel</c> attribute. See <a href="https://tools.ietf.org/html/rfc4287#section-4.2.7.2">RFC 4387 Section 4.2.7.2</a>.
        /// In addition to the five attribute values defined in RFC 4387 ("alternate", "related", "self", "enclosure", "via"), OpenSearch defines "search".
        /// </para>
        /// </remarks>
        public string Relation
        {
            get { return rawLink.RelationshipType; }
        }

        /// <summary>
        /// Human-readable title for the link
        /// </summary>
        public string Title
        {
            get { return rawLink.Title; }
        }

        /// <summary>
        /// MIME type associated with the link.
        /// </summary>
        public string MimeType
        {
            get { return rawLink.MediaType; }
        }

        /// <summary>
        /// Source SyndicationLink value
        /// </summary>
        public System.ServiceModel.Syndication.SyndicationLink RawLink
        {
            get { return rawLink; }
        }
    }
}